package com.mobilebsc.datatype;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;


public class KPI
{
    private int    id;
    private String name;
    private String description;
    private double threshold1;
    private double threshold2;
    private double value;
    private ArrayList<WeakSignal> weakSignals;

    /**
	 * Constructor for empty KPIs
	 */
	public KPI() {
		this.id = -1;
		this.name = "null";
		this.description = "null";
		this.threshold1 = -1.0;
        this.threshold2 = -1.0;
        this.value = -1.0;
        this.weakSignals = new ArrayList<WeakSignal>();
	}
	
	/**
	 * Use constructor to create KPI from JSONObject
	 * @param kpiJSON
	 * @throws JSONException
	 */
	public KPI(JSONObject kpiJSON) throws JSONException {
		this.id = kpiJSON.getInt("id");
		this.name = kpiJSON.getString("name");
		this.description = kpiJSON.getString("description");
		this.threshold1 = kpiJSON.getDouble("threshold1");
        this.threshold2 = kpiJSON.getDouble("threshold2");
        this.value = kpiJSON.getDouble("value");
        this.weakSignals = new ArrayList<WeakSignal>();		
	}
    
    public KPI(int id, String name, String description, double threshold1,
            double threshold2, double value)
    {
        super();
        this.id = id;
        this.name = name;
        this.description = description;
        this.threshold1 = threshold1;
        this.threshold2 = threshold2;
        this.value = value;
        this.weakSignals = new ArrayList<WeakSignal>();
    }

    public int getId()
    {
        return id;
    }

    public void setId(int id)
    {
        this.id = id;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getDescription()
    {
        return description;
    }

    public void setDescription(String description)
    {
        this.description = description;
    }

    public double getThreshold1()
    {
        return threshold1;
    }

    public void setThreshold1(double threshold1)
    {
        this.threshold1 = threshold1;
    }

    public double getThreshold2()
    {
        return threshold2;
    }

    public void setThreshold2(double threshold2)
    {
        this.threshold2 = threshold2;
    }

    public double getValue()
    {
        return value;
    }

    public void setValue(double value)
    {
        this.value = value;
    }
    
    public ArrayList<WeakSignal> getWeakSignals()
    {
        return weakSignals;
    }

    public void setWeakSignals(ArrayList<WeakSignal> weakSignals)
    {
        this.weakSignals = weakSignals;
    }
    
    /**
	 * Returns KPI as a JSONObject
	 * 
	 * @return
	 * @throws JSONException
	 */
	public JSONObject getJSON() throws JSONException {
		JSONObject json = new JSONObject();

		json.put("id", getId());
		json.put("name", getName());
		json.put("description", getDescription());
		json.put("threshold1", getThreshold1());
		json.put("threshold2", getThreshold2());
		json.put("value", getValue());

		return json;
	}
}
